(function(global) {
    /**
     * 数字加密法.构造函数.
     */
    var _NumericalEncryption = (function(numericalSystem) {        
        this.numericalSystem = numericalSystem || 16;   //默认使用16进制.
    }).extend(ujs.data.Encryption);
    /**
     * 加密.
     */
    _NumericalEncryption.prototype.encrypt = function(str) {
        var encryptedCodeArr = [];
        for (var i = 0, strLen = str.length; i < strLen; i++) {
            encryptedCodeArr = encryptedCodeArr.concat('\\', str.charCodeAt(i).toString(this.numericalSystem));
        }
        return encryptedCodeArr.join('');
    };
    /**
     * 解密.
     */
    _NumericalEncryption.prototype.decrypt = function(str) {
        var decryptedCodeArr = [];
        var codeItems = str.split('\\');        
        for (var i = 1, len = codeItems.length; i < len; i++) {
            decryptedCodeArr.push(String.fromCharCode(parseInt(codeItems[i], this.numericalSystem)));
        }
        return decryptedCodeArr.join('');
    };
    
    //--------------------------------------------------------------------------------------------------

    ujs.define('NumericalEncryption', 'ujs.data', function(){
        return _NumericalEncryption;
    });

})(window);

//-------------------------------------------------------------

//测试代码.
/*
 <input id="testStr" placeholder="请输入测试字符串..." />
 <button id="encrypt">加密</button>
 <button id="decrypt">解密</button> 
 //------------------------------------------------------------------ 
 $(function() {
    var encryption = new NumericalEncryption(16);
    $('#encrypt').bind('click', function() {
        $('#testStr').val(encryption.encrypt($('#testStr').val().trim()));
    });
    $('#decrypt').bind('click', function() {
        var trueValue = encryption.decrypt($('#testStr').val().trim());
        $('#testStr').val(trueValue);
    });
});*/
